package com.xiaocikuai.smallchunks.mapper.Product;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xiaocikuai.smallchunks.entity.Advertise.ImgUni;
import com.xiaocikuai.smallchunks.entity.Card.CardChunks;
import com.xiaocikuai.smallchunks.entity.Product.Link;
import com.xiaocikuai.smallchunks.entity.Product.Product;
import com.xiaocikuai.smallchunks.entity.Recode.Recode;
import com.xiaocikuai.smallchunks.entity.Transaction.YshopMaleList;
import com.xiaocikuai.smallchunks.entity.Transaction.YshopRedemptionCode;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

@Mapper
public interface ProductMapper extends BaseMapper<Product> {

    //检索全部产品
    @Select("SELECT * FROM product WHERE clas = #{clasId} AND classes = #{classesId}")
    List<Product> productlist(int clasId, int classesId);



    @Select("SELECT pid FROM yshop_virtual_order WHERE uid = #{uid} AND status = 1 AND ifdis = 0")
    List<Integer> getUnlockPid(int uid);

    @Select("SELECT t_list FROM product WHERE pid = #{pid} ")
    String getShopTidS(int pid);

    //检索某产品单词数量
    @Select("SELECT COUNT(*) FROM card_chunks WHERE product_id = #{pid}")
    int countByProductId(int pid);

    //检索某产品全部单词
    @Select("SELECT * FROM card_chunks WHERE product_id = #{pid}")
    List<CardChunks> allByProductId(int pid);

    @Select("SELECT * FROM product WHERE pid = #{pid}")
    Product getInfo(int pid);

    @Insert("INSERT INTO product_content (pid, cid) VALUES (#{pid}, #{cid})")
    boolean enterWord(int pid, int cid);

    @Select("SELECT * FROM yshop_male_list WHERE tid = #{tid}")
    YshopMaleList getShopinfo(int tid);

    @Select("SELECT introduce FROM yshop_male_list WHERE tid = #{tid} ")
    String getIntroduce(int tid);

    @Select("SELECT detail FROM yshop_male_list WHERE tid = #{tid} ")
    String getDetailImgS(int tid);

    @Select("SELECT * FROM yshop_male_list")
    List<YshopMaleList> getMaleInfo();


    @Delete("DELETE FROM product WHERE pid = #{pid}")
    boolean deleteProductById(int pid);

    @Update("UPDATE product SET name = #{name}, introduce = #{introduce}, version = #{version}, clas = #{clas}, classes = #{classes}, img = #{img}, imgs = #{imgs}, price = #{price}, is_pre = #{isPre}, perpric = #{perpric}, buynum = #{buynum} WHERE pid = #{pid}")
    boolean updateProduct(Product product);

    @Select("SELECT * FROM product WHERE is_pre = #{isPre} ")
    List<Product> getProducts(int isPre);

    @Select("SELECT * FROM product")
    List<Product> getProductss();

    @Select("SELECT price FROM product WHERE  pid = #{pid}")
    float getPriceByPid(int pid);

    @Insert("INSERT INTO yshop_male_list (name, vo_pid, ro_pid, total_price, sale_price, pre_price, pre_time, img, introduce, tag, detail, create_time, update_time) " +
            "VALUES (#{name}, #{voPid}, #{roPid}, #{totalPrice}, #{salePrice}, #{prePrice}, #{preTime}, #{img}, #{introduce}, #{tag}, #{detail}, #{createTime}, #{updateTime})")
    boolean insertMale(YshopMaleList yshopMaleList);

    @Insert("INSERT INTO yshop_redemption_code (tid, code, duid) VALUES (#{tid}, #{code}, #{duid})")
    boolean insertRedemptionCode(YshopRedemptionCode yshopRedemptionCode);


    @Delete("DELETE FROM yshop_male_list WHERE tid = #{tid} " )
    boolean deleteMaleById(int tid);


    @Select("SELECT t_list FROM product WHERE pid = #{pid}")
    String getTlist(int pid);

    @Update("UPDATE product SET t_list = #{newTlist}")
    boolean addPid(String newTlist);

    @Select("SELECT icon FROM uni_img WHERE name = #{name}")
    String getUni(String name);

    @Select("SELECT * FROM img_uni WHERE type = #{type}")
    List<ImgUni> getHomeUni(int type);

    @Select("SELECT count(*) FROM card_chunks WHERE product_id = #{pid}")
    Integer getTotals(int pid);


    //今日新学
    @Select("select cid from recode where uid= #{uid} and time = #{time} and pid= #{pid}")
    Set<Integer> getToday(Integer uid, LocalDate time, Integer pid);

    @Select("select count(*) from recode where uid= #{uid}  and pid= #{pid} and cid = #{cid}")
    int getLastDay(Integer uid, Integer pid,Integer cid);

    @Select("select * from recode where uid= #{uid} and pid= #{pid}")
    Set<Integer> getUser(int uid, int pid);

    @Select("select cid from recode where uid= #{uid}  and review <= #{time} and pid = #{pid}")
    Set<Integer> getReviewAll(int pid, int uid, LocalDate time);
}
